<?php 
session_start();
if (!isset($_SESSION['Username'])) {
                header("location:login.php");
        }
 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inventory</title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<?php include('includes/path.php'); ?>

</head>

<body class="oneColFixCtrHdr">
<div id="container">
<?php include( 'includes/header.php' ); ?>
<?php include( 'includes/menu.php' ); ?>
<?php include( 'includes/status.php' ); ?>

  <div id="mainContent">
<h1>Pending Orders</h1>

<?php 
	// This file inserts the following
	// variables: USER, PASS, DB
	include('db.php'); 

?>
 <?php
        $ROW_NUMBER = 0;
        $CON = mysql_connect( $HOST, $USER, $PASS );
        if (!$CON)
          {
                  die('Could not connect: ' . mysql_error());
          }
        mysql_select_db( $DB );

        $MyQry = "SELECT Users.user_id FROM Users WHERE '$username' = Users.login";
        $fetcheduser = mysql_query($MyQry) or die($MyQry."<br/><br/>".mysql_error());;
        $row = mysql_fetch_assoc($fetcheduser);
        $myuser = $row['user_id'];



        $QRY = 'SELECT request_id, part_id, quantity, date FROM Order_Requests WHERE user_id = '.$myuser.'';
	echo '<table style="width: 100%; border: 5px #aba groove;">';
        echo '<tr style="background-color: #D6B376;"><th style="text-align: center;">Request ID</th><th style="text-align: center; width: 75px;">Part ID</th><th style="width: 75px; text-align: center;">Quantity</th><th style="text-align: center;">Date</th><th style="text-align: center;">Approval</th></tr>';
        $RESULT = mysql_query($QRY);
	while($ROW = mysql_fetch_array($RESULT))
        {
                echo '<tr style="background-color: #';
                if ( $ROW_NUMBER % 2 ){ echo 'FFF;"'; }
                else { echo 'DEDEDE;"'; }

                echo '><td style="padding-left: 5px;">' . $ROW['request_id'] . '</td><td>' . $ROW['part_id'] . '</td><td style="text-align: right;">' . $ROW['quantity'] .  '</td><td style="text-align: right;">' . $ROW['date'] . '</td><td style="text-align: right;">' . 'Pending' . '</td></tr>';
        if ( $ROW_NUMBER % 50 == 0 && $ROW_NUMBER != 0 )
        {
                 echo '<tr style="background-color: #D6B376;"><th style="text-align: center; width: 75px;">Request ID</th><th style="text-align: center; width: 75px;">Part ID</th><th style="width: 75px; text-align: center;">Quantity</th><th style="text-align: center;width: 75px;">Date</th><th style="text-align: center;">Approval</th></tr>';
        }
        $ROW_NUMBER++;
        }
        mysql_close($CON);
        echo '</table>';


?>

<h1>Order History</h1>

<?php
        $myString = '';
        $TABLE = "Purchase_Orders";
        $ROW_NUMBER = 0;
        $CON = mysql_connect( $HOST, $USER, $PASS );
        if (!$CON)
          {
                  die('Could not connect: ' . mysql_error());
          }
        mysql_select_db( $DB );

        $MyQry = "SELECT Users.user_id FROM Users WHERE '$username' = Users.login";
        $fetcheduser = mysql_query($MyQry) or die($MyQry."<br/><br/>".mysql_error());;
        $row = mysql_fetch_assoc($fetcheduser);
        $myuser = $row['user_id'];




        $QRY = 'SELECT Purchase_Orders.user_id, Purchase_Orders.order_id, Purchase_Orders.quantity, Purchase_Orders.fulfillment_date, Purchase_Orders.approved, Purchase_Orders.part_id FROM Purchase_Orders WHERE Purchase_Orders.user_id = '.$myuser.'';
  echo '<table style="width: 100%; border: 5px #aba groove;">';
        echo '<tr style="background-color: #D6B376;"><th style="text-align: center;">Order ID</th><th style="text-align: center;">Part ID</th><th style="text-align: center; width: 75px;">Quantity</th><th style="width: 75px; text-align: center;">Approval Date</th><th style="text-align: center;">Status</th></tr>';
        $RESULT = mysql_query($QRY);
  while($ROW = mysql_fetch_array($RESULT))
        {
                echo '<tr style="background-color: #';
                if ( $ROW_NUMBER % 2 ){ echo 'FFF;"'; }
                else { echo 'DEDEDE;"'; }

                if($ROW['approved']) $myString = "Approved";
                else $myString = "Rejected";

                echo '><td style="text-align: center;">' . $ROW['order_id'] . '</td><td style="text-align: center;">' . $ROW['part_id'] . '</td><td style="text-align: center;">' . $ROW['quantity'] . '</td><td style="text-align: center;">' . $ROW['fulfillment_date'] .  '</td><td style="text-align: center;""> '.$myString.'</td></tr>';
        if ( $ROW_NUMBER % 50 == 0 && $ROW_NUMBER != 0 )
        {
                 echo '<tr style="background-color: #D6B376;"><th style="text-align: center; width: 75px;">Order ID</th><th style="text-align: center; width: 75px;">Quantity</th><th style="width: 75px; text-align: center;">Approval Date</th><th style="text-align: center;width: 75px;">Status</th></tr>';
        }
        $ROW_NUMBER++;
        }
        mysql_close($CON);
        echo '</table>';


?>

<!-- end #mainContent --></div>
<?php include('includes/footer.php'); ?>
<!-- end #container --></div>
</body>
</html>
